import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.*;

@SuppressWarnings("serial")
public class About extends JDialog {
    public static final String IMAGE_PATH = "https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E9%B8%A3%E4%BA%BA&step_word=&hs=0&pn=12&spn=0&di=7264239678495129601&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=2&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=-1&cs=3384167599%2C3440144158&os=1587695288%2C3218571344&simid=3384167599%2C3440144158&adpicid=0&lpn=0&ln=1734&fr=&fmq=1703725076409_R&fm=result&ic=&s=undefined&hd=&latest=&copyright=&se=&sme=&tab=0&width=&height=&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201711%2F29%2F20171129144600_WF5AB.thumb.1000_0.jpeg%26refer%3Dhttp%3A%2F%2Fc-ssl.duitang.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Dauto%3Fsec%3D1706317080%26t%3D503be743424ba25bab23fba0a65adb96&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3B17tpwg2_z%26e3Bv54AzdH3Fks52AzdH3F%3Ft1%3D880dbdmb98&gsm=1e&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&dyTabStr=MCwxLDMsMiw0LDYsNSw3LDgsOQ%3D%3D&lid=11320713073085957481";

    public About(JFrame frame) {
        super(frame, "About [PROGRAM]", true);

        ImageIcon myIcon = null;
        try {
            URL imgUrl = new URL(IMAGE_PATH);
            BufferedImage img = ImageIO.read(imgUrl);
            myIcon = new ImageIcon(img);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            System.exit(-1);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(-1);
        }

        JPanel main = new JPanel(new BorderLayout());

        main.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        JLabel centerLabel = new JLabel(myIcon);
        JLabel name = new JLabel("[PROGRAM]");
        JLabel expandedName = new JLabel("[PROGRAM DESCRIPTION]");
        JLabel copyright = new JLabel("[COPYRIGHT JUNK]");
        JLabel credits = new JLabel("[CREDITS]");

        name.setFont(new Font(name.getFont().getFamily(), Font.BOLD, 18));

        copyright.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));

        int eb = 20;
        centerLabel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));

        JPanel leftPanel = new JPanel();
        leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
        leftPanel.add(name);
        leftPanel.add(Box.createVerticalGlue());
        leftPanel.add(expandedName);
        leftPanel.add(copyright);
        leftPanel.add(credits);
        leftPanel.add(Box.createVerticalGlue());

        main.add(centerLabel, BorderLayout.CENTER);
        main.add(leftPanel, BorderLayout.LINE_START);

        add(main);

        pack();
    }

    public static void main(String[] args) {
        final JFrame frame = new JFrame("GUI");
        JPanel panel = new JPanel();
        panel.add(new JButton(new AbstractAction("About") {

            @Override
            public void actionPerformed(ActionEvent e) {
                About about = new About(frame);
                about.setLocationRelativeTo(frame);
                about.setVisible(true);
            }
        }));
        frame.add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}